<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
        class="-mb-15px"
        :model="queryParams"
        ref="queryFormRef"
        :inline="true"
        label-width="68px"
    >
      <el-form-item label="客户姓名" prop="name" >
        <el-input
            v-model="queryParams.name"
            placeholder="请输入客户姓名"
            clearable
            @keyup.enter="handleQuery"
            class="!w-240px"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 查询</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>
  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="订单编号" align="center" prop="id" width="100px" />
      <el-table-column
          label="派单时间"
          align="center"
          prop="createTime"
          :formatter="dateFormatter"
          width="150px"
      />

      <el-table-column label="申请人" align="center" prop="applyUser" width="150px" />
      <el-table-column label="申请产品" align="center" prop="productId" width="150px" />
      <el-table-column label="预估额度" align="center" prop="amount" width="140px" />
      <el-table-column label="订单状态" align="center" prop="orderState" width="150px">
      <template #default="scope">
        <dict-tag :type="DICT_TYPE.ORDERTYPE" :value="scope.row.orderState" />
      </template>
      </el-table-column>
      <el-table-column label="是否智能匹配" align="center" prop="whether" width="140px" >
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.INTE_MAT_NOT" :value="scope.row.whether" />
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" width="200px">
        <template #default="scope">
          <el-button
              link
              type="primary"
              @click="openForm('look', scope.row.id)"
              checkPermi="['listdetails:user:look']"

          >
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />
  </ContentWrap>

</template>

<script setup lang="ts">
import { ref } from 'vue';
import { dateFormatter } from '@/utils/formatTime'
import * as UsersApi from '@/api/hutai/certificateHolder'
import * as OrderApi from "@/api/hutai/order";
import {DICT_TYPE} from "@/utils/dict";
import {useRouter} from "vue-router";
const router = useRouter()

const { t } = useI18n() // 国际化
defineOptions({ name: 'HutaiClientpoolPool' })


const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据



/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await UsersApi.deleteUsers(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch {}
}


const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  orderNo: null,
  userId: null,
  applyTime: null,
  applyUser: null,
  amount: null,
  practicalAmount: null,
  orderState: null,
  states: null,
  whether: null,
  productId: null,
  agentId: null,
  equityUserId: null,
  createTime: null,
})
const queryFormRef = ref() // 搜索的表单

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    queryParams.userType = 1;
    const data = await OrderApi.getOrderPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}



/** 添加/修改操作 */

/** 添加/修改操作 */




const openForm = (type: string, id: number) => {
  if (type=='look'){
    var index= list._rawValue[id-1].id
    var orderNo=list._rawValue[id-1].orderNo
    router.push(
        {
          path:'/guardPage/listDetails',
          query:{
            orderId:index,
            orderNo:orderNo,
          }
        })
  }
//调用详情页面
}


/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
